﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Edit
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<script type="text/javascript">
if (<%= Session["New"] %> == 1) {
    $(document).ready(function () {
        $("#lblResponse").show();
        $("#lblResponse").html("Added new Category");
        $("#lblResponse").removeClass("error").addClass("success");
        <%= Session["New"] = 0 %>;
    });
}
</script>

<script type="text/javascript">

var Id = <%= Request.Params["Id"] %>;

    function EditCategory() {
        $(document).ready(function () {
                    
            var returnJson =
            {
                "Id": Id,
                "Name": document.getElementById('CategoryName').value, 
                "Year": document.getElementById('Years').value,
                "Description": document.getElementById('Description').value
            };
                
            $.ajax({
                url: '<%= ResolveUrl("~/UserAdministration/Category/EditCategory") %>',
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(returnJson),
                contentType: 'application/json; charset=utf-8',
                success: function (data) {
                alert(data.Check);
                    if (data.Check == 1) {
                        document.getElementById('CatId').value = data.Id;
                        document.getElementById('CategoryName').value = data.Name;
                        document.getElementById('Years').value = data.Year;
                        document.getElementById('Description').value = data.Description;

                        $("#lblResponse").show();
                        $("#lblResponse").html(data.Message);
                        $("#lblResponse").removeClass("error").addClass("success");
                    }
                }
            });
        });
    }

</script>

    <h2 style="width: 200px;height:20px">Edit Category</h2>
    <div style="width:150px;"><div id="lblResponse" style="display: none;"></div></div>

     <fieldset>
     <% foreach (var category in Model.Category)
        { %>
        <fieldset style="float:right; width:230px; height:230px;">
            <div class="ImageCentered">
                <img id="Picture" alt="picture" src="<%= Html.Encode(category.PictureLocation) %>" style="width:230px; height:230px;"/>
            </div>
        </fieldset>
        <div class="form_settings" style="padding-left:30px;width:512px;">
            <p>
                <input type="text" id="CatId" style="display:none;" value="<%= Html.Encode(category.Id) %>"/>
                <span><label for="CategoryName">Category Name:</label></span>
                <input type="text" id="CategoryName" value="<%= Html.Encode(category.Name) %>"/>
            </p>
            <p>
                <span><label for="Years">Years:</label></span>
                <input type="text" id="Years" value="<%= Html.Encode(category.Year) %>"/>
            </p>
            <p>
                <span><label for="Description">Description:</label></span>
                <textarea id="Description" rows="5"><%= Html.Encode(category.Description) %> </textarea>
            </p>

            <p style="padding-left:32px;"><span>&nbsp;</span><input class="submit" type="submit" value="Submit" onclick="EditCategory();" /></p>
        </div>
    <% } %>
    </fieldset>

</asp:Content>
